package com.colin.controller;

import com.colin.pojo.ChanPian;
import com.colin.pojo.ChanPianGongXuTimeTabile;
import com.colin.pojo.Suanfa;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping ("suanfa")
public class SuanFaController {
    @RequestMapping ("to")
    public String tanXin (Suanfa suanfa, HttpSession session) {
        int sum = 0;
        int a[] = new int[10];
        int machineMatrix[][] = new int[10][10];
        int timeMatrix[][] = new int[10][10];
        int countChanPianNumber = (int) session.getAttribute("countChanPianNumber");
        int countJiQiNumber = (int) session.getAttribute("countJiQiNumber");
        suanfa.setProductnumber(countChanPianNumber);
        suanfa.setMachinenumber(countJiQiNumber);
        List<ChanPian> chanPianList = (List<ChanPian>) session.getAttribute("chanPianList");
        List<ChanPianGongXuTimeTabile> listTable = (List<ChanPianGongXuTimeTabile>) session.getAttribute("listTable");
        for (int i = 0; i < chanPianList.size(); i++) {
            a[i] = chanPianList.get(i).getGongxu();
            sum += a[i];
        }
        suanfa.setProcess(a);
        suanfa.setSum(sum);
        int b = 0;
        for (int i = 1; i <= suanfa.getProductnumber(); i++) {
            for (int j = 1; j <= a[i - 1]; j++) {
                machineMatrix[i][j] = listTable.get(b).getJiqi_id();
                timeMatrix[i][j] = listTable.get(b).getTime();
                b++;
            }
        }
        suanfa.setMachineMatrix(machineMatrix);
        suanfa.setTimeMatrix(timeMatrix);
        suanfa.Greedy(0);
        int goodNumber = suanfa.getUpworld();
        session.setAttribute("goodNumber", goodNumber);
        return "four";
    }

}
